/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package servlet;

import dao.InvitationDaoImpl;
import java.io.IOException;
import javax.ejb.EJB;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * @author takamflore
 */
public class InvitationServlet extends HttpServlet {

     private static final long serialVersionUID = 1L;
     @EJB
     InvitationDaoImpl invitationDao;
     
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
    
    }


    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        
        String action= request.getParameter("action");
        
        String forward="";
        int invitationId = Integer.parseInt(request.getParameter("invitation.Id"));
        
        if(action.equalsIgnoreCase("Accept")){
            invitationDao.acceptInvitation(invitationDao.getInvitation(invitationId));
            request.setAttribute("Invitations", invitationDao.getAllInvitation());
            forward="/List_Invitation.jsp";
        
        }else{
            invitationDao.declineInvitation(invitationDao.getInvitation(invitationId));
            request.setAttribute("Invitations", invitationDao.getAllInvitation());
            forward="/List_Invitation.jsp";
        }
        
        RequestDispatcher view = request.getRequestDispatcher(forward);
        view.forward(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    @Override
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>

}
